home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Final Chance 1.1.1 / source / init code ƒ / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.8 KB  |  156 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        main.c
  4.  
  5. Purpose:    This module handles the actual shutdown proc -- creating
  6.             a grafport on the screen and showing the dialog box.
  7.             
  8.  
  9. Final Chance -=- a "do you really want to do this?" dialog on shutdown
  10. Copyright ©1993-4, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "init.h"
  30. #include "main.h"
  31. #include "globals.h"
  32.  
  33. Str255            gTheQuote;
  34. Handle            gChanceDitl;
  35. DialogTHndl        gChanceDlog;
  36.  
  37. void FinalChance(void)
  38. {
  39.     DialogTPtr        dtmp;
  40.     DialogRecord    dlog;
  41.     Handle            newDitl, itemH;
  42.     Rect            *theRect, box;
  43.     int                left, top, item, itemType;
  44.     KeyMap            theKeys;
  45.     unsigned long    startTime;
  46.     
  47.     GetKeys(&theKeys);
  48.     if(theKeys[1] & 0x04)    /* option key down? */
  49.         return;
  50.     
  51.     SetUpA4();
  52.     
  53.     InitGraf(&thePort);
  54.     SetCursor(&arrow);
  55.     
  56.     HLock(gChanceDlog);
  57.     newDitl=gChanceDitl;
  58.     HandToHand(&newDitl);
  59.  
  60.     theRect = (Rect*) *gChanceDlog;
  61.     left = (screenBits.bounds.right - (theRect->right - theRect->left)) / 2;
  62.     top = (screenBits.bounds.bottom - (theRect->bottom - theRect->top)) / 3;
  63.     
  64.     if(top < (GetMBarHeight() + 1))
  65.         top = GetMBarHeight() + 1;
  66.     theRect->right += left - theRect->left;
  67.     theRect->left = left;
  68.     theRect->bottom += top - theRect->top;
  69.     theRect->top = top;
  70.  
  71.     dtmp=*gChanceDlog;
  72.     NewDialog(&dlog, theRect, dtmp->title, dtmp->visible, dtmp->procID,
  73.                 (WindowPtr)-1L, dtmp->goAwayFlag, dtmp->refCon, newDitl);
  74.     
  75.     ParamText(gTheQuote, "\p", "\p", "\p");
  76.     
  77.     GetDItem(&dlog, 6, &itemType, &itemH, &box);
  78.     InsetRect(&box, -4, -4);
  79.     SetDItem(&dlog, 6, itemType, (Handle)OutlineDefaultButton, &box);
  80.     
  81.     ShowWindow(&dlog);
  82.     
  83.     GetDateTime(&startTime);
  84.     GetDItem(&dlog, 8, &itemType, &itemH, &box);
  85.     /* DrawModuleIcon needs access to the start time, but has no access to our globals, */
  86.     /* so we'll store the time in the refcon of a control for lack of anything cleaner */
  87.     SetCRefCon((ControlHandle)itemH, startTime);
  88.  
  89.     item=0;
  90.     do { ModalDialog((ProcPtr)ProcOFilter, &item); } while ((item!=1) && (item!=2));
  91.     
  92.     HideWindow(&dlog);
  93.     CloseDialog(&dlog);
  94.     
  95.     HUnlock(gChanceDlog);
  96.     DisposeHandle(newDitl);
  97.     
  98.     RestoreA4();
  99.     
  100.     if (item==2)
  101.         ExitToShell();
  102. }
  103.  
  104. pascal Boolean ProcOFilter(DialogPtr theDialog, EventRecord *theEvent, short *theItem)
  105. {
  106.     unsigned char    theChar;
  107.     unsigned long    theTime, startTime;
  108.     int                itemType;
  109.     Rect            box;
  110.     Handle            itemH;
  111.     
  112.     switch (theEvent->what)
  113.     {
  114.         case keyDown:
  115.         case autoKey:
  116.             theChar=theEvent->message & charCodeMask;
  117.             if ((theChar==0x0d) || (theChar==0x03))
  118.             {
  119.                 *theItem=1;
  120.                 return TRUE;
  121.             }
  122.             if ((theChar==0x1b) ||
  123.                 ((theEvent->modifiers & cmdKey) && (theChar=='.')))
  124.             {
  125.                 *theItem=2;
  126.                 return TRUE;
  127.             }
  128.             break;
  129.         case nullEvent:
  130.             GetDateTime(&theTime);
  131.             GetDItem(theDialog, 8, &itemType, &itemH, &box);
  132.             startTime=(unsigned long)GetCRefCon((ControlHandle)itemH);
  133.             if (theTime-startTime>=60)
  134.             {
  135.                 *theItem=1;
  136.                 return TRUE;
  137.             }
  138.             break;
  139.     }
  140.     
  141.     return FALSE;
  142. }
  143.  
  144. pascal void OutlineDefaultButton(DialogPtr myDlog, short itemNum)
  145. {
  146.     short    itemType;
  147.     Handle    itemH;
  148.     Rect    box;
  149.     
  150.     GetDItem(myDlog, 1, &itemType, &itemH, &box);
  151.     PenSize(3, 3);
  152.     InsetRect(&box, -4, -4);
  153.     FrameRoundRect(&box, 16, 16);
  154.     PenNormal();
  155. }
  156.